
import psutil
from multiprocessing import Pool
import os
import shutil
import json

class PoolTest(object):
    def __init__(self):
        self.ab = 3
        print("cpu_count: %d" % psutil.cpu_count())
        self._pool = Pool(processes=psutil.cpu_count())

    def task(self, test_case_file_id):
        print('_run')
        print(self.__dict__) 
   

    def run(self):
        """
        """
        # _pool = Pool(processes=psutil.cpu_count())
        for i in range(5):
            print("task: %d" % i)
            # 异步函数执行 task, 并返回结果
            self._pool.apply_async(func=self.task, args=(i, ))
           
        self._pool.close()
        self._pool.join()

    def __getstate__(self):
        self_dict = self.__dict__.copy()
        del self_dict['_pool']
        return self_dict

    def __setstate__(self, state):
        self.__dict__.update(state)

if __name__ == '__main__':
    aa = JudgeClient()
    aa.run()